package com.thread.singleton;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.function.Consumer;

/**
 * @author wangyingjie
 * @date
 * @remark 无锁单例提高效率
 */
public class SingletonDemo {

    private SingletonDemo() {
    }

    private static class SingletonUtil{
        private static SingletonDemo instance = new SingletonDemo();
    }

    /**
     * 利用静态内部类，第一次调用初始化时创建单例
     * @return
     */
    public SingletonDemo getInstance(){
        return SingletonUtil.instance;
    }

    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(8000);
            //accept开启服务，会导致线程进入阻塞状态等待
            Socket socket = serverSocket.accept();

            ArrayList<Integer> objects = new ArrayList<>();
            Consumer intConsumer = System.out::println;
            Consumer intConsumer2 = System.out::println;
            objects.stream().forEach(intConsumer.andThen(intConsumer2));
        } catch (IOException e) {
            e.printStackTrace();
        }
        String name = "222";
        System.out.println(name);
        name = "33";
        System.out.println(name);

    }
}
